package com.bjdd.jdy.ui.userCenter;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjdd.jdy.R;
import com.bjdd.jdy.base.BaseActivity;
import com.bjdd.jdy.entity.InfoBean;
import com.bjdd.jdy.entity.User;
import com.bjdd.jdy.util.ImageUtil;
import com.bjdd.jdy.util.L;
import com.bjdd.jdy.util.SpUtil;
import com.bjdd.jdy.util.StatusBarUtil;
import com.bjdd.jdy.util.T;
import com.liuguangqiang.ipicker.IPicker;

import java.io.File;
import java.io.IOException;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.BufferedSink;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

public class UserCenterActivity extends BaseActivity<UserCenterPresenter, UserCenterModel> implements UserCenterContract.View {

    @Bind(R.id.toolbar_back)
    ImageView toolbarBack;
    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.tv_mobile)
    TextView tvMobile;
    @Bind(R.id.tv_realname)
    TextView tvRealname;
    @Bind(R.id.tv_idcard)
    TextView tvIdcard;
    @Bind(R.id.tv_rz)
    TextView tvRz;
    @Bind(R.id.img_head)
    ImageView imgHead;
    private User user;
    private String headPhoto;
    @Override
    public int getLayoutId() {
        return R.layout.activity_user_center;
    }

    @Override
    public void initView() {
        StatusBarUtil.setColor(this,getResources().getColor(R.color.toolbar_bg),0);
        title.setText("个人信息");
    }


    @OnClick({R.id.toolbar_back,R.id.all_change_head_img})
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.toolbar_back:
                finish();
                break;
            case R.id.all_change_head_img:
                IPicker.setLimit(1);
                IPicker.setOnSelectedListener(new IPicker.OnSelectedListener() {
                    @Override
                    public void onSelected(List<String> paths) {
                        if (paths!=null && paths.size()>0){
                            headPhoto = paths.get(0);
                            File file = new File(headPhoto);
                            //RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"),file);
                            presenter.CompressImg(file);
                        }
                    }
                });
                IPicker.open(context);
                break;
        }
    }

    private void uploadHead(File file){

    }

    @Override
    public void infoSuccess(InfoBean infoBean) {
        tvMobile.setText(infoBean.getTel());
        tvRealname.setText(infoBean.getRealName());
        tvIdcard.setText(infoBean.getIdCard());
        tvRz.setText(infoBean.getStatus());
        imageUtil.loadCircleImage(infoBean.getPhoto(),imgHead);
    }

    @Override
    public void headPhotoSuccess() {
        imageUtil.loadCircleImage(headPhoto,imgHead);
    }

}
